package com.zstu.mall.dao;

import com.zstu.mall.common.BaseRepository;
import com.zstu.mall.entity.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author     : wuyc
 * @description: ProductDao
 * @date       : Created in 2019/11/24
 */
public interface ProductDao extends BaseRepository<Product, String> {

    /**
     * 通过分类查找商品列表
     *
     * @param type
     * @param pageable
     * @return
     */
    List<Product> findByType(String type, Pageable pageable);

    List<Product> findByTypeIn(List<String> types,Pageable pageable);

    /**
     * 通过标题搜索商品
     *
     * @param name
     * @param pageable
     * @return
     */
    List<Product> findByNameIsLike(String name, Pageable pageable);

    /**
     * 查找某个日期之后上架的商品
     * @param gmtCreate
     * @param pageable
     * @return
     */
    List<Product> findByGmtCreateAfter(Date gmtCreate, Pageable pageable);

    /**
     * 查找热门商品(status = 3)
     * @param status
     * @param pageable
     * @return
     */
    List<Product> findByStatusOrderByString1Desc(String status, Pageable pageable);

    /**
     * 查询最新商品，最近上新的20个商品
     * @param pageable
     * @return
     */
    @Query(value = "SELECT * FROM (SELECT  * FROM product ORDER BY gmt_create DESC limit 0,20) a",nativeQuery = true)
    List<Product> findNew(Pageable pageable);

    /**
     * 根据活动查找商品
     * @param activityId
     * @param pageable
     * @return
     */
    List<Product> findByActivityId(String activityId, Pageable pageable);

}
